<extend name="public@base5"/>

<block name="main">

    <div class="wrap">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link" href="{:url('task/index')}">任务列表</a>
            </li>
            <li class="nav-item">
                <a class="nav-link active" href="{:url('task/add')}">添加任务</a>
            </li>
        </ul>
        <form method="post" class="js-ajax-form margin-top-20" action="admin/task/save">
            <input type="hidden" name="id" value="{$id|default=0}">
            <input type="hidden" name="task_type" value="{$task_type|default=0}">
            <div class="row mb-3">
                <label for="input-tag_name" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>任务名称</label>
                <div class="col-md-4 col-sm-4">
                    <input type="text" class="form-control" id="input-tag_name" name="task_name" value="{$task_name|default=''}" placeholder="任务名称">
                </div>
            </div>
            <div class="row mb-3">
                <label for="input-task_key" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>任务类型</label>
                <div class="col-md-4 col-sm-4">
                    <select id="input-task_key" name="task_key" class="form-control">
                    <foreach name="tasktypes" item="vo">{$vo}</foreach>
                    </select >
                </div>
            </div>
            <div class="row mb-3">
                <label for="input-task_req" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>任务目标</label>
                <div class="col-md-4 col-sm-4">
                    <input type="number" class="form-control" id="input-task_req" name="task_req" value="{$task_req|default=''}" placeholder="任务目标" >
                </div>
            </div>
            <div class="row mb-3">
                <label for="input-task_reward" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>任务奖励</label>
                <div class="col-md-4 col-sm-4">
                    <input type="number" class="form-control" id="input-task_reward" name="task_reward" value="{$task_reward|default=''}" placeholder="任务奖励" >
                </div>
            </div>
            <div class="row mb-3">
                <label for="input-task_desc" class="col-sm-2 col-form-label text-sm-end"><span class="form-required">*</span>任务内容</label>
                <div class="col-md-4 col-sm-4">
                    <input type="text" class="form-control" id="input-task_desc" name="task_desc" value="{$task_desc|default=''}" placeholder="任务内容" >
                </div>
            </div>
            
            <div class="row mb-3">
                <label for="input-task_medal" class="col-sm-2 col-form-label text-sm-end">奖励勋章ID</label>
                <div class="col-md-1 col-sm-1">
                    <input type="number" class="form-control" id="input-task_medal" onChange="check_medal()" name="task_medal" value="{$task_medal|default='0'}" placeholder="勋章ID" >
                     
                </div>
                <div id="medal_info" class="col-md-3 col-sm-3">
                    
                </div>
                如果任务没有勋章,则不需要填写
            </div>

            <div class="row mb-3">
                <div class="offset-md-2 col-sm-10">
                    <button type="submit" class="btn btn-primary js-ajax-submit">
                        <i class="fa fa-save fa-fw"></i> {:lang('SAVE')}
                    </button>
                </div>
            </div>
        </form>
    </div>
</block>

<block name="scripts">
    <script src="__STATIC__/js/mall.js"></script>
    <script>
        /***/
        function check_medal(){
           var metId = $('#input-task_medal').val();
           if(metId>0){
               $.get('{:url("medal_info")}',{"id":metId},function(d){
                   if(d && d.data && d.data.id){
                       var data = d.data;
                       var html = '<label>'+data.medal_name+'</label><img src="'+data.medal_url+'" width=100/>';
                       $('#medal_info').html(html);
                   }else{
                       $('#medal_info').html('');
                   }
               });
           }else{
               $('#medal_info').html('');
           }
        }
        check_medal();
    </script>
</block>